<!DOCTYPE html>
<html lang="en">
 <!-- 219971337杨俊 -->
 <!-- 219970119刘佳迪 -->
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小米商城登录页面</title>
  <link rel="stylesheet" href="./index.css" />
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> 
</head>
 
<body>
  <div id="app"></div>
  <template id="root">
    <div class="box">
      <!-- 左侧背景 -->
      <div class="left"></div>
      <!-- 右侧内容 -->
      <div class="right">
        <div class="right_header">
          <!-- logo -->
          <div class="logo">
            <img src="https://s1.ax1x.com/2023/04/14/ppzXmFI.png" alt="" />
            <span>小米账号</span>
          </div>
          <!-- 右侧选项 -->
          <div class="r_option">
            <a href="javascript:;">用户协议</a>
            <a href="javascript:;">隐私政策</a>
            <a href="javascript:;">帮助中心</a>
            <select name="" id="">
              <option value="">中文(简体)</option>
              <option value="">中文(繁体)</option>
              <option value="">English</option>
            </select>
          </div>
        </div>
        <div class="right_body">
          <div>
            <img v-if="isSao" @click="changeStaue" class="img" src="https://s1.ax1x.com/2023/04/16/p99rIpt.jpg" alt="" srcset="">
            <img v-else @click="changeStaue" class="img" src="https://s1.ax1x.com/2023/04/16/p99siBF.jpg" alt="" srcset="">
          </div>
          <!-- 账号登录 -->
          <div v-if="isSao">
            <div class="log_reg">
              <a :class="isActice?['isActice']:[]" @click="login">登录</a>
              <a :class="isActice?[]:['isActice']" @click="register">注册</a>
            </div>
            <!-- 登录 -->
            <div class="login_content" v-if="isActice">
              <form action="">
                <div class="uname">
                  <input type="text" placeholder="邮箱/手机号码/小米ID" class="ipt" v-model="username" />
                </div>
                <div class="pwd">
                  <input type="password" placeholder="密码" class="ipt" v-model="password" />
                </div>
                <div class="change">
                  <input type="checkbox" v-model="isChecked" @click="l_change" />
                  <span>已阅读并同意小米账号<a href="javascript:;">用户协议</a>和
                    <a href="javascript:;">隐私政策</a>
                  </span>
                </div>
              </form>
              <button class="log_btn" @click="goLogin">登录</button>
              <div class="forget">
                <a href="javascript:;">忘记密码？</a>
                <a href="javascript:;">手机号登录</a>
              </div>
              <div class="other">其他方式登录</div>
              <div class="other_content">
                <img :src="item.path" alt="" v-for="item in otherLogin" :key="item.key" />
              </div>
            </div>
            <!-- 注册 -->
            <div class="register_content" v-else>
              <form action="">
                <div>
                  <select class="ipt" v-model="cityvalue">
                    <option :value="item.value" v-for="item in city">{{ item.text }}</option>
                  </select>
                </div>
                <div>
                  <input type="text" placeholder="手机号" class="ipt" v-model.number="phone" />
                </div>
                <div class="yzm">
                  <!-- <input type="password" placeholder="密码" class="ipt" v-model.trim="r_password" /> -->
                  <input type="text" placeholder="请输入验证码" class="ipt" maxlength="4" v-model.number="yzm" />
                  <span v-if="isSend" @click="changeVuale">获取验证码</span>
                  <span v-else>{{second}}s重新发送</span>
                </div>
                <div class="change">
                  <input type="checkbox" v-model="isChecked1" @click="r_change" />
                  <span>已阅读并同意小米账号<a href="javascript:;">用户协议</a>和
                    <a href="javascript:;">隐私政策</a>
                  </span>
                </div>
                <!-- <input type="submit" class="reg_btn" @click="goRegister" value="注册" /> -->
              </form>
              <button class="reg_btn" @click="goRegister">注册</button>
              <div class="Unavailable">收不到验证码？</div>
              <div class="other">其他方式登录</div>
              <div class="other_content">
                <img :src="item.path" alt="" v-for="item in otherLogin" :key="item.key" />
              </div>
            </div>
          </div>
          <!-- 扫码登录 -->
          <div v-else>
            <!-- 文字 -->
           <h1>扫码登录 安全快捷</h1>
           <div style="display: flex;justify-content: center;align-items: center;height: 300px;">
            <img class="erweima" src="https://s1.ax1x.com/2023/04/16/p99sQBD.jpg" alt="" srcset="">
           </div>
           <view class="font">请使用小米手机/米家等小米旗下APP扫码登录</view>
           <view class="font1">支持扫码登录的App</view>
           <view style="display:flex;justify-content:space-around;padding: 80px;">
            <img src="https://s1.ax1x.com/2023/04/16/p99sIUJ.jpg" alt="" srcset="" class="image">
            <img src="https://s1.ax1x.com/2023/04/16/p99s7CR.jpg" alt="" srcset="" class="image">
            <img src="https://s1.ax1x.com/2023/04/16/p99sH81.jpg" alt="" srcset="" class="image">
           </view>
          </div>
        
        </div>
      </div>
    </div>
  </template>
 
  <script>
    Vue.createApp({
      template: '#root',
      data() {
        return {
          isActice: true,
          username: '',
          password: '',
          yzm: '',
          phone: '',
          isSend: true,
          isSao:true,
          second: 30,
          isChecked: false,
          isChecked1: false,
          userList: [],
          cityvalue: 'China',
          city: [
            { value: 'China', text: '中国' },
            { value: 'mg', text: '美国' },
            { value: 'other', text: '其他' }
          ],
          otherLogin: [
            {
              id: 1,
              name: '支付宝',
              path: 'https://s1.ax1x.com/2023/04/14/p9SEuQJ.png'
            },
            {
              id: 2,
              name: '微信',
              path: 'https://s1.ax1x.com/2023/04/14/p9SEGFK.png'
            },
            {
              id: 3,
              name: 'QQ',
              path: 'https://s1.ax1x.com/2023/04/14/p9SEJJO.png'
            },
            {
              id: 4,
              name: '微博',
              path: 'https://s1.ax1x.com/2023/04/14/p9SEUQH.png'
            }
          ]
        }
      },
      methods: {
        // 登录注册切换
        login() {
          this.isActice = !this.isActice
        },
        register() {
          this.isActice = !this.isActice
        },
        // 用户条款勾选
        l_change() {
          this.isChecked = !this.isChecked
        },
        r_change() {
          this.isChecked1 = !this.isChecked1
        },
        // 验证码
        changeVuale() {
          this.isSend = false
          var interval = setInterval(() => {
            let times = --this.second
            this.second = times < 10 ? '0' + times : times //小于10秒补 0
          }, 1000)
          setTimeout(() => {
            clearInterval(interval)
            this.second = 30
            this.isSend = true
          }, 30000)
        },
        // 扫码
        changeStaue() {
          this.isSao = !this.isSao;
        },
        // 登录
        goLogin() {
          if (this.username == '' || this.password == '') {
            alert('账号或密码为空，请输入')
          } else {
            if (!this.isChecked) {
              alert('请同意用户条款')
            } else {
              console.log(JSON.parse(localStorage.getItem('user')));
              console.log(this.userList);
              this.userList.forEach(item => {
                if (item.phone == this.username && item.yzm == this.password) {
                  alert('登录成功')
                } else {
                  alert('登录失败')
                }
              })
            }
          }
        },
        // 注册
        goRegister() {
          if (this.phone == '' || this.yzm == '') {
            alert('输入不能为空')
          } else {
            if (!this.isChecked1) {
              alert('请同意用户条款')
            } else {
              const regCN = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
              if (!regCN.test(this.phone)) {
                alert('请输入正确的手机号')
              } else {
                if (this.yzm === 1234) {
                  let isRegister
                  this.userList.forEach(item => {
                    if (item.phone == this.phone) {
                      isRegister = true
                    } else {
                      isRegister = false
                    }
                  })
                  if (isRegister) {
                    alert('用户名已存在')
                  } else {
                    let data = {
                      id: +new Date(),
                      phone: this.phone,
                      yzm: this.yzm,
                      city: this.cityvalue
                    }
                    this.userList.push(data)
                    localStorage.setItem('user',JSON.stringify(data))
                    alert('注册成功')
                    console.log(this.userList)
                    this.phone = ''
                    this.yzm = ''
                  }
                }
                else {
                  alert('验证码输入错误！')
                }
              }
            }
          }
        }
      }
    }).mount('#app')
  </script>
</body>
 
</html>